package com.ziytek.web.citizen.listener;

import com.ziytek.web.citizen.constant.NumConstant;
import com.ziytek.web.citizen.event.PushEvent;
import com.ziytek.web.citizen.service.PushDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * 信息推送
 *
 * @author fenghx
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PushEventListener {
    private final PushDataService pushDataService;

    @Async("myAsyncExecutor")
    @EventListener
    @Order(NumConstant.INT_ZERO)
    public void pushEventListener(PushEvent event) {
        Assert.notNull(event, "消息推送 event is null");
        Assert.hasLength(event.getCabinetNo(), "信息推送 cab is null");

        // 先推送首界面的实时数据
        pushDataService.realtimeDataQueryAndPush(String.valueOf(Integer.parseInt(event.getCabinetNo())));

    }
}
